<template>
  <!-- 服务管理 -->
  <div class="innerPageTable-box-OneTwo value-set-list-wrap innerPageTable-out-flex">
    <!-- 搜索区域 -->
    <SelfAdaption>
      <Form
        :model="searchForm"
        ref="serviceForm"
        slot="adaption-bar"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item prop="vsCode" :label="'报表名称'">
          <Input
            type="text"
            v-model.trim="searchForm.serviceName"
            :placeholder="'请输入'"
            @on-enter="searchValueSet"
          ></Input>
        </Form-item>

        <!-- 查询\重置按钮 -->
        <Form-item prop="button" class="search-solt-btn">
          <RPButton optType="search" @click="searchValueSet()" />
        </Form-item>
      </Form>
    </SelfAdaption>
    <InnerPageTable ref="valueSetTable" :config="pageTableConfig"> </InnerPageTable>
  </div>
</template>

<script>
import { tableColumns } from './columns'
import managementPage from './managementPage.vue'
import groupManagementPage from './groupManagementPage.vue'
import coverPage from '../specialManagement/coverageStatistics2.0/coverPage/index.vue'
import codeTestPage from './codeTest/index.vue'
import coverageStatisticsPage from '@/views/specialManagement/coverageStatistics/index.vue'
import coverageStatisticsPage2 from '@/views/specialManagement/coverageStatistics2.0/index.vue'
import implementationPlanPage from '@/views/specialManagement/implementationPlan/index.vue'
import groupImplementationPlanPage from '@/views/specialManagement/groupImplementationPlan/index.vue'
import statisticePage from './statistics/statisticePage.vue'
import statisticePage2 from './statistics/statisticePage2.vue'
import coverStatistice from '../specialManagement/coverageStatistics2.0/statistice/index.vue'
import permission from '@/mixin/permission'
import coverApi from '../../api/cover'
// 1-任务表 2-现状表 3-目标表 4-计算表
const TABLE_TYPE_TASK = '1'
const TABLE_TYPE_STATUS = '2'
const TABLE_TYPE_TARGET = '3'
const TABLE_TYPE_COUNT = '4'
export default {
  name: 'special',
  mixins: [permission],
  data() {
    return {
      searchForm: {
        serviceName: ''
      },
      pageTableConfig: {
        loadDataFn: this.getServiceList,
        columns: tableColumns.bind(this)(),
        autoFirst: false //默认 就是 false, 要配置在这里
      }
    }
  },
  computed: {},
  created: function() {},
  beforeMount: function() {},
  mounted: function() {
    this.init()
    this.searchValueSet()
  },
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    init() {
      if (!this.$route.query.modal) return
      const { modal } = this.$route.query

      if (modal === 'implementationPlanPage') {
        //业务单元实施任务表
        this.checkFun({ id: 1 })
      }
      if (modal === 'coverageStatisticsPage') {
        //数字化覆盖度表
        this.checkFun({ id: 2 })
      }
      if (modal === 'groupImplementationPlanPage') {
        //集团实施方案任务表
        this.checkFun({ id: 3 })
      }
    },
    // 查看
    managementFun(row) {
      if (row.id == 2) {
        this.$Message.warning({
          content: '功能尚未开放，请07月13日开始操作',
          duration: 3
        })
        return
      }
      let components = null
      if (row.id == 1) {
        components = managementPage
      } else if (row.id == 3) {
        components = groupManagementPage
      } else if (row.id == 4) {
        components = coverPage
      }
      new this.$sidelipPage(components, {
        props: {
          id: row.id || '',
          type: row.type,
          typeName: row.name,
          oldTypeName: row.oldName
        }
      })
    },
    statisticsFun(row) {
      new this.$sidelipPage(row.type === 1 ? statisticePage : coverStatistice, {
        props: {
          id: row.id || '',
          type: row.type,
          typeName: row.name
        }
      })
    },
    codeTest() {
      coverApi.getCodeList('IFRAME_OUT_URL').then(res => {
        let rescords = res.data.records
        if (rescords.length > 0) {
          const list = []
          rescords.forEach(item => {
            if (['COVER_PAGE'].includes(item.vsiKey)) {
              list.push(item)
            }
          })
          this.urlCodeList = list
        }
        this.singleIframeUrl = this.urlCodeList[0].vsiDescription
        window.open(this.singleIframeUrl, '_blank')
      })
    },
    // 跳转覆盖度表统计页面
    coverStatistics() {
      coverApi.getCodeList('IFRAME_OUT_URL').then(res => {
        let rescords = res.data.records
        if (rescords.length > 0) {
          const list = []
          rescords.forEach(item => {
            if (['COVER_STATISTICS_PAGE'].includes(item.vsiKey)) {
              list.push(item)
            }
          })
          this.urlCodeList = list
        }
        this.singleIframeUrl = this.urlCodeList[0].vsiDescription
        window.open(this.singleIframeUrl, '_blank')
      })
    },

    //（集团，业务单元实施）操作
    checkFun(row) {
      if (row.id == 2) {
        this.$Message.warning({
          content: '功能尚未开放，请07月13日开始操作',
          duration: 3
        })
        return
      }
      if (row.id == 1) {
        new this.$sidelipPage(implementationPlanPage, {
          props: { $route: this.$route }
        })
      } else if (row.id == 2) {
        new this.$sidelipPage(coverageStatisticsPage, {
          props: { $route: this.$route }
        })
      } else if (row.id == 3) {
        new this.$sidelipPage(groupImplementationPlanPage, {
          props: { $route: this.$route }
        })
      } else if (row.id == 4) {
        if (!this.$store.state.userBu) {
          this.$Message.error({
            content: '未获取的用户单位信息，请联系管理员',
            duration: 3
          })
        } else {
          new this.$sidelipPage(coverageStatisticsPage2, {
            props: { $route: this.$route }
          })
        }
      }
    },
    getServiceList(tableObj) {
      let { responseProcess, param } = tableObj
      coverApi.getPermittedTableList().then(res => {
        let list = []
        if (this.hasPermission('GROUP_VIEW_DATA')) {
          list.push({
            oldName: '华润集团数字化转型行动计划实施方案任务表',
            name: '华润集团数字化转型行动计划实施方案任务表',
            id: 3,
            type: 3
          })
        }
        let tableTypeList = res.data.data || []
        if (tableTypeList.includes(TABLE_TYPE_TASK)) {
          list.push({
            oldName: '数字化转型专项实施方案任务表',
            name: '业务单元数字化转型行动计划实施方案任务表',
            id: 1,
            type: 1
          })
        }
        if (
          tableTypeList.includes(TABLE_TYPE_STATUS) &&
          tableTypeList.includes(TABLE_TYPE_TARGET) &&
          tableTypeList.includes(TABLE_TYPE_COUNT)
        ) {
          list.push({ oldName: '关键业务环节数字化覆盖度', name: '关键业务环节数字化覆盖度', id: 2, type: 2 })
        }
        if (this.hasPermission('COVER_READ_20') || this.hasPermission('COVER_WRITE_20')) {
          list.push({ oldName: '关键业务环节数字化覆盖度2.0', name: '关键业务环节数字化覆盖度2.0', id: 4, type: 4 })
        }
        let records = list.filter(item => item.name.includes(this.searchForm.serviceName))
        responseProcess({
          pageNum: 1,
          pageSize: 10,
          pages: 1,
          records,
          total: records.length
        })
      })
    },
    //搜索
    _sleep(time) {
      return new Promise(function(resolve) {
        setTimeout(resolve, time)
      })
    },
    searchValueSet() {
      this.$refs['valueSetTable'].load(this.searchForm)
    }
  },
  watch: {},
  directives: {}
}
</script>
